# -*- coding: utf-8 -*-#
#-------------------------------------------------------------------------------
# 建立者:        Young  
# Name:         demo9.06
# Description:
# Author:       $赵怡蕾
# Date:         2019/3/5
#-------------------------------------------------------------------------------

class NegativeException(Exception):
    pass
class ZeroException(Exception):
    pass

class SpecialCalc:
    def add(self,x,y):
        if x < 0 or y < 0:
            # 为异常指定异常信息
            raise NegativeException("x和y都不能小于0")
        return x + y
    def sub(self,x,y):
        if x - y < 0:
            # 为异常指定异常信息
            raise NegativeException("x与y的差值不能小于0")
        return x - y
    def mul(self,x,y):
        if x == 0 or y == 0:
            # 为异常指定异常信息
            raise ZeroException("x和y都不能等于0")
        return x * y
    def div(self,x,y):
        return x / y

while True:
    try:
        calc = SpecialCalc()
        expr = input("请输入要计算的表达式，例如，add(1,2):")
        if expr == ":exit":
            break
        result = eval('calc.' + expr)
        print("计算结果：{:.2f}".format(result))
    # 同时捕捉NegativeException和ZeroException异常，并为其指定一个异常对象变量e
    except (NegativeException,ZeroException) as e:
        # 输出相应的异常信息
        print(e)
    # 捕捉ZeroDivisionError异常
    except ZeroDivisionError as e:
        # 输出相应的异常信息
        print(e)
    except:
        print("******其他异常******")